package org.jeecg.common.serial;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * Jackson序列化配置
 * Long类型序列化到JS会失去精准度，转化成String类型，序列化配置
 * 使用方法：Long类型字段添加注解 @JsonSerialize(using = JsonLongSerializer.class )
 *
 * @author yann
 * @date 2020/2/20
 */
public class JsonLongSerializer extends JsonSerializer<Long> {
    @Override
    public void serialize(Long aLong, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeString(Long.toString(aLong));
    }
}
